home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 9
/
FM Towns Free Software Collection 9.iso
/
t_os
/
tool
/
extdrv
/
src
/
disk.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-16
|
2KB
|
114 lines
#include "extdrv.h"
#include "regdef.h"
#include "disk.h"
#include "dir.h"
#include "file.h"
#include "buffer.h"
#include "dos.h"
#include "extern.h"
extern int drvmap[];
extern u_char *dmabuf;
void drive_chk()
{
char buf[256];
extern u_long max_cluster_size;
if (dp->n_rdir == 0){
if (drvInit(dp->drvno, dp->devno & 0x0f, dp->part) < 0)
return;
if (dp->n_rdir != 0){ /* ready */
inquiry(dp->devno, buf);
dp->removable = (buf[1] & 0x80);
}
inv_buffer(dp->devno);
inv_root(dp->devno);
inv_fat(dp->devno);
} else {
if (reqsense(dp->devno, buf) == 0){
if (buf[0] == 0x70 && (buf[2] & 0x0f) == UNIT_ATN){
#ifdef DEBUG
auxputs("<DISK#");
auxprinthex((u_long)(dp->devno & 0x0f));
auxputs(" media changed>\r\n");
#endif
drvInit(dp->drvno, dp->devno & 0x0f, dp->part);
inv_buffer(dp->devno);
inv_root(dp->devno);
inv_fat(dp->devno);
dp->removable &= ~0x0100;
}
}
}
if (dp->clustsize > max_cluster_size){
#ifdef DEBUG
auxprinthex(max_cluster_size);
#endif
flush_buffer(NULL, 0, BUF_FILE, TRUE);
flush_buffer(NULL, 0, BUF_DIR, TRUE);
#ifdef DEBUG
auxputs("-->");
#endif
max_cluster_size = dp->clustsize;
#ifdef DEBUG
auxprinthex(max_cluster_size);
#endif
cluster_init();
#ifdef DEBUG
auxputs("\r\n");
#endif
}
}
static u_short getDrvFree(struct drvinfo far *d)
{
u_short i, free;
free = 0;
for (i = 2; i < d->n_clust + 2; i++){
if (!fat_decode(d, i))
free++;
}
d->freearea = (u_long)free;
return(free);
}
getDiskFree()
{
u_int drv;
long freearea;
struct idrvinfo far *d;
struct drvinfo far *p;
int org_apl3;
org_apl3 = get_apl3();
set_apl3(org_apl3 | 0x80);
#ifdef DEBUG
auxputs("getDiskFree ");
#endif
d = (struct idrvinfo far *)FAR(regs.es, regs.di);
drv = d->curdir[0] - 'A';
p = drives + drvmap[drv];
if ((freearea = p->freearea) < 0L){
freearea = (long)getDrvFree(p) & 0xffffL;
p->fatid = (u_long)fat_read(p, 0L);
}
regs.ax = (p->fatid << 8) | p->cluster;
regs.bx = p->n_clust;
regs.cx = p->sectsiz;
regs.dx = freearea;
#ifdef DEBUG
auxprinthex((u_long)regs.ax);
auxputs(" ");
auxprinthex((u_long)regs.bx);
auxputs(" ");
auxprinthex((u_long)regs.cx);
auxputs(" ");
auxprinthex((u_long)regs.dx);
auxputs("\r\n");
#endif
set_apl3(org_apl3);
OK_RET
}